
package ctype

import (
	"database/sql/driver"
	"fmt"
	"strings"
)

type TimeRange struct {
	BeginAt string `json:"begin_at"`
	EndAt   string `json:"end_at"`
}

type TimeRangeArray []TimeRange

// Scan implements the Scanner interface.
func (tr *TimeRange) Scan(value interface{}) error {
	// fmt.Printf("time_range=>%v,%s", value, string(value.([]byte)))
	str := string(value.([]byte))
	val := str[1:len(str)-1]
	vals := strings.Split(val, ",")
	tr.BeginAt =  vals[0]
	tr.EndAt =  vals[1]
	return nil
}

// Value implements the driver Valuer interface.
func (tr TimeRange) Value() (driver.Value, error) {
	return fmt.Sprintf("(%s,%s)", tr.BeginAt, tr.EndAt), nil
}